<template>
  <el-cascader
    :value="value"
    size="mini"
    :options="treeData"
    :props="props"
    separator="-"
    @change="changeValue"
  />
</template>

<script>
import { getDepartment } from '@/api/department'
import { transListToTreeData } from '@/utils/index'
export default {
  name: '',
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data () {
    return {
      treeData: [],
      props: {
        value: 'id',
        label: 'name'
      }
    }
  },
  created () {
    this.getDepartment()
  },
  methods: {
    async getDepartment () {
      const data = await getDepartment()
      const res = transListToTreeData(data, 0)
      this.treeData = [...res]
      console.log(this.treeData)
    },
    changeValue (list) {
      if (list.length) {
        this.$emit('input', list[list.length - 1])
      } else {
        this.$emit('input', null)
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
